package com.example.zhangguoqing.homeofpet.Tip;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zhangguoqing.homeofpet.R;

import java.util.ArrayList;
import java.util.HashMap;

public class ListViewAdapter extends BaseAdapter implements View.OnClickListener {
    private Context context;
    private ArrayList<HashMap<String,Object>>data;
    Bean bean=null;
    public ListViewAdapter(Context context, ArrayList<HashMap<String,Object>>data){
        this.context=context;
        this.data=data;
    }
    @Override
    public void onClick(View v) {
       // ((MainActivity)context).click(v);

    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View holder, ViewGroup parent) {
        if(holder==null){
            bean=new Bean();
            LayoutInflater layoutInflater=LayoutInflater.from(context);
            holder=layoutInflater.inflate(R.layout.info_listitem,null);
            bean.imageView=(ImageView)holder.findViewById(R.id.image);
            bean.itemName=(TextView)holder.findViewById(R.id.itemName);

            bean.detail=(ImageView)holder.findViewById(R.id.detail);
            holder.setTag(bean);
        }
        else
        {
            bean=(Bean)holder.getTag();

        }
        bean.imageView.setBackgroundResource((int)data.get(position).get("image"));
        bean.itemName.setText((String)data.get(position).get("itemName"));
        bean.detail.setOnClickListener(this);
        bean.detail.setTag(position);
        return  holder;
    }
}
